<template>
    <div>
        <el-form :model="Achievement" style="width: 100%;" label-width="80px" ref="Achievements">
            <ElFormItem label="任务描述">
                <ElInput placeholder="请输入你的进度说明" v-model="Achievement.Desc"></ElInput>
            </ElFormItem>
         <!--   <ElFormItem label="任务图片">
                <el-upload ref="uploadRef" class="upload-demo"
                    v-model:file-list="fileList"
                    :action="global.apiurl+'/images/list'"
                    list-type="picture-card"
                    :auto-upload="false"
                    :on-success="handleAvatarSuccess"
                    :on-change="handleChange">
                    <template #trigger>
                        <el-icon><Plus /></el-icon>
                    </template>
                </el-upload>

            </ElFormItem> -->
            <ElFormItem label="是否完成">
                <ElCheckbox border v-model="Achievement.IsEnd"  label="是否完成"  ></ElCheckbox>
            </ElFormItem>
            <ElFormItem>
                <ElButton @click.prevent="submit(Achievements)" type="primary">提交</ElButton>
            </ElFormItem>
        </el-form>
    </div>
</template>

<script setup lang="ts">
import { ElMessage, FormInstance, UploadInstance, UploadProps } from 'element-plus';
import { ref } from 'vue';
import global from '@/request/global';
import achievementapi from '@/api/achievementapi';

// const uploadRef = ref<UploadInstance>()
const props = defineProps({
    Id: Number
})
const emits = defineEmits(["CloesDialog"])
const fileList = ref<any[]>([]);
const Achievement = ref({
    TaskId:props.Id,
    Images: "",
    Desc: "",
    IsEnd:false
});
var dd = 0;
const Achievements = ref<FormInstance>();
const submit = (fromEl: FormInstance | undefined) => {
    // console.log(uploadRef.value)
   //uploadRef.value!.submit();
   achievementapi.acsubmit(Achievement.value).then(res=>{
   	console.log("Achievement.value=",Achievement.value)
       if (res.code > 0) {
           ElMessage.success("提交成功")
           emits("CloesDialog","submit")
       }else{
           ElMessage.error("提交失败")
       }
   }).catch(err=>{
       console.log(err)
   })
    if (!fromEl) return;

}
const handleChange:UploadProps['onChange'] = (uploadFile, uploadFiles) => {
  dd = uploadFiles.length;
}
//图片
var dsd = 0
var imgs: any[] = [];
const handleAvatarSuccess: UploadProps['onSuccess'] = (
    response,
    uploadFile
) => {
    dsd ++;
    imgs.push(response.data[0])
    //console.log()
    if (dd == dsd) {
        Achievement.value.Images = imgs.join(',')
   //      achievementapi.acsubmit(Achievement.value).then(res=>{
			// console.log("Achievement.value=",Achievement.value)
   //          if (res.code > 0) {
   //              ElMessage.success("提交成功")
   //              emits("CloesDialog","submit")
   //          }else{
   //              ElMessage.error("提交失败")
   //          }
   //      }).catch(err=>{
   //          console.log(err)
   //      })
    }
    //imageUrl.value = URL.createObjectURL(uploadFile.raw!)
}

</script>

<style scoped></style>